#ifndef FFMPEGDEMO_AUDIOCHANNEL_H
#define FFMPEGDEMO_AUDIOCHANNEL_H

#include "BaseChannel.h"
#include "JNICallBackHelper.h"

extern "C" {
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
//对音频数据进行重采样
#include "libswresample/swresample.h"
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
}


class AudioChannel : public BaseChannel {
private:
    pthread_t pid_audio_decode;
    pthread_t pid_audio_play;

public:
    SLObjectItf engineObject = 0;  //引擎对象
//  引擎接口
    SLEngineItf engineInterface = 0;
//  混音器
    SLObjectItf outputMixObject = 0;
//  播放器接口
    SLObjectItf bqPlayerObject = 0;
//   播放器接口
    SLPlayItf bqPlayInterface = 0;
//   播放器队列接口
    SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue = 0;

    double audio_time; // TODO 音视频同步 1.1

    int out_channel;
    int out_simple_size;
    int out_sample_rate;
    int out_buffer_size;
    uint8_t *out_buffer =0;

    SwrContext *swr_ctx = 0;

    AudioChannel(int stream_index, AVCodecContext *codecContext, AVRational rational);

    void stop();

    ~AudioChannel();

    void start();

    void audio_decode();

    void audio_play();

    int getPCM();

    void audio_stop_(AudioChannel *pChannel);
};


#endif //FFMPEGDEMO_AUDIOCHANNEL_H
